#include "insertthread.h"

#include <QDebug>
#include <QTimer>
#include <QDateTime>

InsertThread::InsertThread(QObject *parent) : QObject(parent)
{

}

InsertThread::~InsertThread()
{
    qInfo() << "[INSERT] Thread Release Resources";
}

void InsertThread::startThread_slot()
{
    qInfo() << "[INSERT] Thread Start";

    QTimer *m_timer = new QTimer;
    connect(m_timer, &QTimer::timeout, this, &InsertThread::onInsert_slot);
    m_timer->start(100);
}

void InsertThread::exitThread_slot()
{
    qInfo() << "[INSERT] Thread Exit";
}

void InsertThread::onInsert_slot()
{
    qDebug() << "[INSERT] On Insert Slot";

    int ret = 0;
    QQueue<DISEASE_INFO> m_diseInfoQueue;

    for (int i = 0; i < 100; i++)
    {
        QString dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");

        DISEASE_INFO m_diseInfo;
        m_diseInfo.algorithm_time = dateTime;
        m_diseInfo.autoApproval = "0";
        m_diseInfo.azimuth = "136.2";
        m_diseInfo.cameraAntennaAngle = "23";
        m_diseInfo.cameraDistance = "1.2";
        m_diseInfo.cameraVehicleAngle = "0";
        m_diseInfo.camera_type = "1";
        m_diseInfo.collect_time = dateTime;
        m_diseInfo.device_id = "T00032";
        if (i % 5 == 0)
        {
            m_diseInfo.dm_data_company_id = "no_id";
            m_diseInfo.sceneId = "no_road";
        }
        else
        {
            m_diseInfo.dm_data_company_id = "400463";
            m_diseInfo.sceneId = "14543451234";
        }
        m_diseInfo.gcjDamage = "";
        m_diseInfo.gpsStatus = "4";
        m_diseInfo.latitude = "31.123456";
        m_diseInfo.longitude = "121.123456";
        m_diseInfo.road_type = "3";
        m_diseInfo.srcpic_dir = "/home/nvidia/DATA/Hardware/2025_03_13/T00032/camera/front/13/26/";
        m_diseInfo.respic_dir = "/home/nvidia/DATA/Hardware/2025_03_13/T00032/camera/res/13/26/";
        m_diseInfo.picture_name = "T00032-2025-03-13_13-24-36-456.jpg";
        m_diseInfo.speed = "96.2";
        m_diseInfo.res = "[wegtsdrhtyrtgrewrfsedsdfdshgertfewsaf]";
        m_diseInfo.picResolution = "1920,1080";
        m_diseInfo.pitch = "31";

        m_diseInfoQueue.enqueue(m_diseInfo);
    }

    // Insert DR Data To Database
    ret = database.drDataInsert(m_diseInfoQueue);
    if (ret != 0)
    {
        qWarning() << "[INSERT] DR Data Insert Failed" << ret;
    }
}
